package com.example.multithread;

import com.xncoding.starter.service.LeeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @ClassName AppCommand
 * @Description 计算1加到100的原始算法
 * @Author leejiliang
 * @DateTime 2020/4/27 2:07 PM
 * @Version 1.0
 */
@Component
public class AppCommand implements CommandLineRunner {
	private Logger logger = LoggerFactory.getLogger(AppCommand.class);
	@Autowired
	private LeeService leeService;
	@Override
	public void run(String... args) throws Exception {

		logger.info(leeService.wrap(leeService.getClass().toString()));

		//Extend Thread
//		Example01 e1 = new Example01(1L, 33000L);
//		Example01 e2 = new Example01(33001L, 67000L);
//		Example01 e3 = new Example01(67001L, 1000000L);
//		e1.start();
//		e2.start();
//		e3.start();
//		e1.join();
//		e2.join();
//		e3.join();
//		Example01.result.stream().reduce(Long::sum).ifPresent(i -> logger.info("最终结果是: "+i));
////		logger.info(Thread.currentThread().getName());
//
//		//implement Runnable
//		Example02 e1 = new Example02();
//		Example02 e2 = new Example02();
//
//		Thread t1 = new Thread(e1);
//		Thread t2 = new Thread(e2);
//
//		t1.setName("t1");
//		t2.setName("t2");
//
//		t1.start();
//		t2.start();
	}
}
